package com.changgou.search.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.search.service.ESManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/manager")
public class ESManagerController {

    @Autowired
    private ESManagerService esManagerService;

    @GetMapping("/create")
    public Result create(){
        esManagerService.creatMappingAndIndex();;
        return new Result(true, StatusCode.OK,"创建索引库成功");
    }

    @GetMapping("/importAll")
    public Result importAll(){
        esManagerService.importAll();;
        return new Result(true, StatusCode.OK,"导入全部数据成功");
    }

////    通过response对象设置响应头跳转页面
//    @RequestMapping("/test")
//    public void test(HttpServletResponse response,String id){
//        response.setStatus(302);
//        response.setHeader("location","https://www.baidu.com/");
//    }
}
